﻿//-----------------------------------------------------------------------
// <copyright file="WriteLock.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System.Threading;

#endregion

namespace GateShift.Services.SDK.Threading.Locking
{
    /// <summary>
    /// Locking class used to gain a write lock on an object
    /// </summary>
    public class WriteLock : LockBase
    {
        /// <summary>
        /// Initializes a new instance of the WriteLock class
        /// </summary>
        /// <param name="lockObject">ReaderWriterLockSlim containing the locking states</param>
        public WriteLock(ReaderWriterLockSlim lockObject)
            : base(lockObject)
        {
            if (LockObject != null)
            {
                Locks.GetWriteLock(LockObject);
            }
        }

        /// <summary>
        /// Disposes the lock
        /// </summary>
        public override void Dispose()
        {
            if (LockObject != null)
            {
                Locks.ReleaseWriteLock(LockObject);
            }
        }
    }
}
